package operation;
import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28792
 * Date: 2023-11-19
 * Time: 12:27
 */
public class FindOperation implements IOPeration{

    @Override
    public void work(BookList bookList) {
        System.out.println("查找图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请写出你要查找的图书书名：");
        String name = scanner.nextLine();
        int currentSize = bookList.getUsedSize();
        for(int i = 0; i < currentSize;i++){
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                System.out.println("存在这本书，信息如下： ");
                System.out.println(book);
                return; //找到就结束程序
            }
        }
        //没有return出去，就说明没有找到
        System.out.println("不存在"+name+"这本书");
    }
}
